package net.ikenway.springboot.demo.Utils;

import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.validation.ObjectError;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author MasterKenway <zk@ikenway.net>
 * @Description
 * @date Created Date 12/12/2020
 */
public class ValidateErrorMsgUtil {
    public static List<String> getFormatMsg(List<ObjectError> errors) {
        return errors.stream()
                .map(DefaultMessageSourceResolvable::getDefaultMessage)
                .collect(Collectors.toList());
    }

    public static String getFirstFormatMsg(List<ObjectError> errors) {
        return errors.get(0).getDefaultMessage();
    }
}
